﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;
using Zocono.Infrastructure.Common;
using Zocono.WCS.Application.AppConfigureManage;
using Zocono.WCS.Domain.EntityInfo;
using Zocono.WCS.Infrastructure.ApllicationDto.DtoWcsManage;

namespace Zocono.WCS.WebApi.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ScWorkModelInfoController : ControllerBase
    {
        public ScWorkModelApp _ScWorkModelApp;
        private readonly ILogUtil _logger;

        public ScWorkModelInfoController(ILogUtil logger, ScWorkModelApp scWorkModelApp)
        {
            _logger = logger;
            _ScWorkModelApp = scWorkModelApp;
        }

        [HttpGet]
        public async Task<HeaderResult<List<ScWorkModelInfo>>> GetScWorkModelInfoAsync()
        {
            HeaderResult<List<ScWorkModelInfo>> headerResult = new HeaderResult<List<ScWorkModelInfo>>();
            try
            {
                var res = await _ScWorkModelApp.GetScWorkModelInfo();
                if (res != null)
                {
                    headerResult.IsSucceed = true;
                    headerResult.Message = "查询成功";
                    headerResult.Result = res;
                }
                else
                {
                    headerResult.IsSucceed = false;
                    headerResult.Message = "查询失败";
                }
            }
            catch (System.Exception ex)
            {
                headerResult.IsSucceed= false;
                headerResult.Message = ex.Message; 
            }
           return headerResult;
        }

        [HttpPost]
        public async Task<HeaderResult<bool>> UpdateScWorkModelInfoAsync(ScWorkModelInfoDto scWorkModelInfoDto)
        {
            HeaderResult<bool> headerResult = new HeaderResult<bool>();
            try
            {
                var res= await _ScWorkModelApp.UpdateScWorkModelInfo(scWorkModelInfoDto);
                if (res)
                {
                    headerResult.IsSucceed = true;
                    headerResult.Message = "更新成功";
                }
                else
                {
                    headerResult.IsSucceed = false;
                    headerResult.Message = "更新失败";
                }
            }
            catch (System.Exception ex)
            {
                headerResult.IsSucceed = false;
                headerResult.Message = ex.Message;
            }
            return headerResult;
        }
    }
}
